package com.md.config.database.slave;

import com.md.config.database.slave.balancer.ISlaveSourceLoadBalancer;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@RequiredArgsConstructor
@AutoConfigureAfter(SlaveDataSourceConfig.class)
public class DataSourceConfig {
  @Bean
  public DataSourceRouting dataSourceRouting(final SlaveDataSourceConfig slaveDataSourceConfig,
                                             @Autowired(required = false) final ISlaveSourceLoadBalancer
                                               slaveSourceLoadBalancer) {
    return new DataSourceRouting(slaveDataSourceConfig, slaveSourceLoadBalancer);
  }

  @Bean
  public SlaveInterceptor slaveSQLInterceptor() {
    return new SlaveInterceptor();
  }

}
